<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 300px;
            height: 200px;
            background-color: blue;
        }
    </style>
</head>

<body>
    <div class="box">嘉琪</div>
    <input type="button" value="测试" id="btn">
    <script>

        // 功能：获取dom元素的样式属性
        // 参数：
        //    dom元素
        //    样式属性名

        // 返回值:样式属性名对应的值

        function getStyle(dom, attribute) {
            if (dom.currentStyle) {
                return dom.currentStyle[attribute];
            } else {
                return window.getComputedStyle(dom)[attribute];
            }
        }
        var btn = document.getElementById("btn");
        btn.onclick = function () {
            // // var w=getstyle(document.querySelector(".box"),"width");
            // var w = getStyle(document.getElementsByClassName("box")[0], "width")
            // console.log("w", w);
            var scrolltop=document.documentElement.scrollTop||document.body.scrollTop;
            console.log("scrolltop",scrolltop);
        }
    </script>
</body>

</html>